<template>
	<view class="fixed-bottom">
		<view class="b-delete b-delete-txt" @click="onDelGoods" v-if="isDel">删除</view>
		<view class="b-copy" @click="onCopyGoods" v-if="isEdit">复制</view>
		<view class="b-copyreader" @click="editGoods" v-if="isEdit">编辑</view>
	</view>
</template>

<script>
	import config from "../../js/conf/Config.js";
	import lang from "../../js/conf/Lang.js";
	import eventCtrl from "../../js/event/EventCtrl.js";
	import https from "../../js/https/Https.js";
	import staticConst from "../../js/const/StaticConst.js";
	
	
	export default {
		props:["goodId","isEdit","isDel"],
		data() {
			return {
			};
		},
		
		methods:{
			//****** 删除产品 DEL_GOODS ******//
			async onDelGoods()
			{
				let d = {};
				d.content = lang.tipTxt.sureDelGdTxt,
				d.showCancel = true;
				lang.showWin(d,delGood);
				let that = this;
				async function delGood(data)
				{
					if(data.confirm)
					{
						let param = {};
						param.goods_id = that.goodId;
						https.delGoods(param,callBack);
					}
				}
				
				function callBack(data)
				{
					if(data && data.status == 1)
					{
						that.$msg({title : lang.tipTxt.delGoodsTxt});
						uni.$emit(eventCtrl.ACTION_GOODS_EVENT,that.goodId);
					}
				}
			},
			
			/***编辑产品***/
			async editGoods()
			{
				this.opstionGoods(staticConst.ACT_GOODS_EIDT);
			},
			
			/****操作产品****/
			async opstionGoods(actType)
			{
				let that = this;
				let param = {};
				param.goods_id = this.goodId;
				https.editGoods(param,callBack);
				
				function callBack(data)
				{
					if(data.status == 1)
					{
						let gdTimeTpl = data.data && data.data.goodsInfo ? data.data.goodsInfo.time_tpl : 0; //产品模板时间
						let timeTpl =  data.data && data.data.tpl_info ? data.data.tpl_info.time_tpl : 0; //模板最后改动时间
						if(gdTimeTpl == timeTpl)
						{
							data.data.actType = actType; //编辑
							uni.$emit(eventCtrl.EDIT_GOODS_EVENT,data.data);
						}
						else
						{
							//提示模板发生变化，要使用新的模板
							let obj = {};
							obj.content = lang.tlpTxt.title;
							obj.showCancel = true;
							obj.data = data.data;
							lang.showWin(obj,tlpCallBack);
						}
					}
				}
				
				function tlpCallBack(res)
				{
					if(res && res.confirm) //确认使用新模板
					{
						res.data.actType = actType; //编辑
						uni.$emit(eventCtrl.EDIT_GOODS_EVENT,res.data);
					}
				}
			},
			
			/*****复制产品****/
			async onCopyGoods()
			{
				let d = {};
				d.content = lang.tipTxt.copyGdTxt,
				d.showCancel = true;
				lang.showWin(d,copyGoods);
				let that = this;	
				function copyGoods(data)
				{
					if(data.confirm)
					{
						that.opstionGoods(staticConst.ACT_GOODS_COPY);
					}
				}
			}
		}
	}
</script>

<style lang="scss">
	.fixed-bottom
	{
		height: 60px;
		right: 0;
		bottom: 0;
		background: #FFF;
		border-top: 1px solid #ECECEC;
		border-bottom: 1px solid #ECECEC;
		overflow-x: auto;
		z-index: 99;
		font-size: 16px;
		display: flex;
		justify-content: flex-end;
		.b-copyreader
		{
			cursor: pointer;
			width: 200px;
			height: 60px;
			background: #3388FF;
			color: #FFF;
			text-align: center;
			line-height: 60px;
		}
		
		.b-copyreader:hover
		{
			opacity: .9;
		}
		.b-copyreader:active
		{
			opacity: .8;
		}
		.b-delete, .b-copy
		{
			cursor: pointer;
			width: 100px;
			height: 60px;
			text-align: center;
			line-height: 60px;
			color: #333
		}
		
		.b-delete-txt
		{
			color: #FF0000;
		}
		
		.b-delete:hover, .b-copy:hover
		{
			background-color: #EEE;
		}
		
		.b-copy:active, .b-delete:active, 
		{
			background-color: #DEDEDE;
		}
	}
</style>
